package com.wang.web.controller;

import com.wang.doc.CourseDoc;
import com.wang.hrm.query.CourseQuery;
import com.wang.hrm.util.AjaxResult;
import com.wang.hrm.util.PageList;
import com.wang.repository.CourseElasticsearchRepository;
import com.wang.service.ESService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ESController {

    @Autowired
    private CourseElasticsearchRepository courseElasticsearchRepository ;
    @Autowired
    private ESService esService;
    //保存
    @RequestMapping(value = "/es/onLineCourse",method = RequestMethod.POST)
    public AjaxResult onLineCourse(@RequestBody CourseDoc courseDoc){
        courseElasticsearchRepository.save(courseDoc);
        return AjaxResult.me();
    }
    //保存
    @RequestMapping(value = "/es/offLineCourse",method = RequestMethod.POST)
    public AjaxResult offLineCourse(@RequestBody CourseDoc courseDoc){
        courseElasticsearchRepository.delete(courseDoc);
        return AjaxResult.me();
    }
    //查询课程
    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public PageList<CourseDoc> searchCourse(@RequestBody CourseQuery courseQuery){
        return esService.searchCourse(courseQuery);
    }
}
